<template>
  <div>
    <el-button style="margin-bottom: 10px;" type="primary" @click="handlereset">刷新</el-button>
    <FilterTable
      ref="table"
      columnsRef="partInventoryDetailssslls"
      :columns="columns"
      :datakey="'rows'"
      height="auto"
      maxHeight="350"
      :fetchapi="fetchapi"
      :params="fetchParams"
      :onColumnsChange="columns => (this.columns = columns)"
    ></FilterTable>
    <div class="btnWrap">
      <el-button @click="handleClose">关 闭</el-button>
    </div>
  </div>
</template>

<script>
import { dictionary } from '@/utils/dictMixin';
import { queryPartStockDetailReportDetailData } from '@/api/part/report/partreport';

export default {
  mixins: [dictionary],
  props: {
    userList: {
      type: Array,
      default: () => []
    },
    row: { type: Object }
  },
  data() {
    return {
      columns: this.createTableColumns(),
      fetchapi: queryPartStockDetailReportDetailData,
      fetchParams: { xhrAbort: true }
    };
  },
  created() {
    // console.log(this.row, '1231');
    // console.log(this.userList, '1238');
    this.fetchParams = Object.assign(this.fetchParams, {
      storageCode: this.row.STORAGE_CODE,
      srotagePositionCode: this.row.STORAGE_POSITION_CODE,
      partNo: this.row.PART_NO,
      xhrAbort: false
    });
  },
  methods: {
    createTableColumns() {
      return [
        {
          title: '入出库单编号',
          dataIndex: 'SHEET_NO',
          sorter: true,
          filter: true,
          filterType: 'input',
          showOverflowTooltip: true
        },
        {
          title: '执行日期',
          dataIndex: 'OPERATE_DATE',
          dateFormat: 'yyyy-MM-dd',
          sorter: true,
          filter: true,
          filterType: 'date-range',
          showOverflowTooltip: true
        },
        {
          title: '入出库方式',
          dataIndex: 'IN_OUT_TYPE',
          sorter: true,
          filter: true,
          filterType: 'checkbox',
          filterItems: this.createDictList('8249'),
          showOverflowTooltip: true,
          render: params => {
            return <span>{this.createDictText(params.row.IN_OUT_TYPE, '8249')}</span>;
          }
        },
        {
          title: '入出数量',
          dataIndex: 'QUANTITY',
          sorter: true,
          filter: true,
          filterType: 'number',
          showOverflowTooltip: true
        },
        {
          title: '库存数量',
          dataIndex: 'STOCK_QUANTITY',
          sorter: true,
          filter: true,
          filterType: 'number',
          showOverflowTooltip: true
        },
        {
          title: '含税入出单价',
          dataIndex: 'IN_OUT_TAXED_PRICE',
          showOverflowTooltip: true,
          sorter: true,
          filter: true,
          filterType: 'number',
          precision: 2
        },
        {
          title: '含税入出金额',
          dataIndex: 'IN_OUT_TAXED_AMOUNT',
          showOverflowTooltip: true,
          sorter: true,
          filter: true,
          filterType: 'number',
          precision: 2
        },
        {
          title: '不含税成本金额',
          dataIndex: 'COST_AMOUNT',
          sorter: true,
          filter: true,
          filterType: 'number',
          showOverflowTooltip: true,
          precision: 2
        },
        {
          title: '单位代码',
          dataIndex: 'UNIT_CODE',
          sorter: true,
          filter: true,
          filterType: 'input',
          showOverflowTooltip: true
        },
        {
          title: '单位名称',
          dataIndex: 'UNIT_NAME',
          sorter: true,
          filter: true,
          filterType: 'input',
          showOverflowTooltip: true
        },
        {
          title: '经手人',
          dataIndex: 'OPERATOR',
          render: props => {
            return <span>{this.userList[props.row.OPERATOR]}</span>;
          }
        },
        {
          title: '操作员',
          dataIndex: 'CREATED_BY',
          render: props => {
            return <span>{this.userList[props.row.CREATED_BY]}</span>;
          }
        },
        // {
        //   title: '对应单编号',
        //   dataIndex: 'a13'
        // },
        {
          title: '对应单位',
          dataIndex: 'CUSTOMER_NAME',
          sorter: true,
          filter: true,
          filterType: 'input',
          showOverflowTooltip: true
        },
        {
          title: '车牌号',
          sorter: true,
          filter: true,
          filterType: 'input',
          dataIndex: 'LICENSE'
        },
        {
          title: '备注',
          sorter: true,
          filter: true,
          filterType: 'input',
          dataIndex: 'a16'
        }
      ];
    },
    // 点击刷新
    handlereset() {
      this.fetchParams.xhrAbort = true;
      this.fetchParams.xhrAbort = false;
    },
    // 点击关闭
    handleClose() {
      this.$emit('close');
    }
  }
};
</script>

<style scoped>
.btnWrap {
  position: absolute;
  left: 0px;
  bottom: 0px;
  right: 0px;
  z-index: 9;
  border-top: 1px solid rgb(233, 233, 233);
  padding: 10px 20px;
  background: rgb(255, 255, 255);
  text-align: right;
}
</style>
